package com.qcby.demo;

/**
 * 示例操作
 */
public class SampleOperation implements TransactionOperation {
    private String name;
    private boolean success; // 用于模拟成功与失败

    public SampleOperation(String name, boolean success) {
        this.name = name;
        this.success = success;
    }

    @Override
    public void execute() throws Exception {
        System.out.println("执行操作: " + name);
        if (!success) {
            throw new Exception(name + " 操作失败");
        }
    }

    @Override
    public void rollback() {
        System.out.println("回滚操作: " + name);
    }
}
